package com.itany.corejava.code07_面向对象.租车系统;

import java.util.Scanner;

/**
 * @author: 石小俊
 * @date: 2023年03月09日 13:31
 * @version: 1.0
 */
public class Test {
    public static void main(String[] args) {
        System.out.println("*********************欢迎使用租车系统*********************");
        Scanner sc = new Scanner(System.in);

        // 准备一个机动车数组,用于存放所有租赁的机动车
        MotorVehicle[] vehicles = new MotorVehicle[100];
        // 初始化一个索引号,便于将对应的机动车存放到数组中
        int index = 0;

        Customer customer = new Customer();
        System.out.print("请输入您的姓名:");
        customer.setName(sc.next());
        System.out.print("请输入您的手机号码:");
        customer.setPhone(sc.next());

        while (true) {
            System.out.print("请选择要租赁的车辆类型(1.轿车 2.客车 3.退出):");
            int choice = sc.nextInt();
            if (choice == 1) {
                // 如果是轿车,选择轿车的型号
                System.out.print("请选择车辆型号(1.宝马X1 2.奔驰GLC 3.保时捷卡宴 4.劳斯莱斯古斯特):");
                int num = sc.nextInt();
                switch (num) {
                    case 1:
                        // 将当前所选择的轿车实例化
                        MotorVehicle vehicle = new Car("苏A00001", "宝马", CarConstant.BMW_X1);
                        // 将实例化后的轿车存放到机动车数组中
                        // 每次存放之后,数组的索引+1
                        vehicles[index++] = vehicle;
                        break;
                    case 2:
                        vehicles[index++] = new Car("苏A00002", "奔驰", CarConstant.BENZ_GLC);
                        break;
                    case 3:
                        vehicles[index++] = new Car("苏A00003", "保时捷", CarConstant.PORSCHE_CAYENNE);
                        break;
                    case 4:
                        vehicles[index++] = new Car("苏A00004", "劳斯莱斯", CarConstant.ROLLS_ROYCE_GHOST);
                        break;
                    default:
                        System.out.println("您输入的选项有误,请重新输入");
                        break;
                }
            } else if (choice == 2) {
                // 选择对应的客车
                System.out.print("请选择对应的客车(1.19座的考斯特 2.25座奔驰凌特 3.31座宇通客车 4.45座金龙客车):");
                int num = sc.nextInt();
                switch (num) {
                    case 1:
                        vehicles[index++] = new Bus("苏A00005", "考斯特", 19);
                        break;
                    case 2:
                        vehicles[index++] = new Bus("苏A00006", "奔驰凌特", 25);
                        break;
                    case 3:
                        vehicles[index++] = new Bus("苏A00007", "宇通", 31);
                        break;
                    case 4:
                        vehicles[index++] = new Bus("苏A00008", "金龙", 45);
                        break;
                    default:
                        System.out.println("您输入的选项有误,请重新输入");
                        break;
                }
            } else if (choice == 3) {
                break;
            } else {
                System.out.println("您输入的选项有误,请重新输入");
            }
        }

        System.out.print("请输入租赁的天数:");
        int day = sc.nextInt();
        System.out.println("-------------------------------------");
        System.out.println("客户:" + customer.getName() + ",您租赁的车辆信息:");
        System.out.println("车牌号\t\t品牌");
        // 计算所有车辆的总租金
        double money = 0;
        for (int i = 0; i < index; i++) {
            money += vehicles[i].rent(day);
            System.out.println(vehicles[i].getNo() + "\t\t" + vehicles[i].getBrand());
        }
        System.out.println("-------------------------------------");
        System.out.println("共租赁了" + index + "辆机动车,租赁了" + day + "天,总租金为:" + money + "元");

    }
}
